package com.aku.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {

    /*定义bean SqlSessionFactoryBean 用户产生SqlSessionFactory对象*/
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean (DataSource dataSource){
        SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
        /*设置模型类别名扫描*/
        sqlSessionFactory.setTypeAliasesPackage("com.aku.entity");
        /*设置数据源*/
        sqlSessionFactory.setDataSource(dataSource);
        return sqlSessionFactory;
    }

    /*定义bean 返回MapperScannerConfigurer 对象用于mapper扫描 */
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        /*需要扫描的mapper数据*/
        mapperScannerConfigurer.setBasePackage("com.aku.dao");
        return mapperScannerConfigurer;
    }
}
